def print_file_content(file_name):
    """
    打印文件内容到控制台
    :param file_name: 文件路径
    :return: None
    """
    f = None
    try:
        f = open(file_name, 'r', encoding='UTF-8')
        print('---------------------')
        print(f.read())
        print('---------------------')
    except FileNotFoundError as e:
        print(F'错误！！文件{file_name}不存在👉{e}')
    except Exception as e:
        print(F'打印文件内容到控制台：{e}')
    finally:
        if f:
            f.close()


def append_to_file(file_name, data):
    """
    往给定文件中追加内容
    :param file_name: 给定文件路径
    :param data: 追加的内容
    :return: None
    """
    f = open(file_name, 'a', encoding='UTF-8')
    f.write(F'\n{data}')
    f.close()


if __name__ == '__main__':
    my_file_name = 'E:\\PythonBasicKnowledge\\07 文件操作\\poem.txt'
    # 读取内容
    print_file_content(my_file_name)

    # 追加内容
    append_to_file(my_file_name, '🍀🐇沉舟侧畔千帆过，病树前头万木春📕轻舟已过万重山')

    # 读取内容
    print_file_content(my_file_name)
